package com.ruoyi.admin.controller;

import com.ruoyi.admin.domain.RewardExchangeVO;
import com.ruoyi.admin.service.IRewardExchangeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.RewardExchange;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 兑换记录Controller
 * 
 * @author xukai
 * @date 2024-12-22
 */
@RestController
@RequestMapping("/reward/exchange")
public class RewardExchangeController extends BaseController
{
    @Autowired
    private IRewardExchangeService rewardExchangeService;

    /**
     * 查询兑换记录列表
     */
    //@PreAuthorize("@ss.hasPermi('reward:exchange:list')")
    @GetMapping("/list")
    public TableDataInfo list(RewardExchange rewardExchange)
    {
        startPage();
        List<RewardExchangeVO> list = rewardExchangeService.selectRewardExchangeList(rewardExchange);
        return getDataTable(list);
    }

    /**
     * 导出兑换记录列表
     */
    //@PreAuthorize("@ss.hasPermi('reward:exchange:export')")
    @Log(title = "兑换记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RewardExchange rewardExchange)
    {
        List<RewardExchangeVO> list = rewardExchangeService.selectRewardExchangeList(rewardExchange);
        ExcelUtil<RewardExchangeVO> util = new ExcelUtil<RewardExchangeVO>(RewardExchangeVO.class);
        util.exportExcel(response, list, "兑换记录数据");
    }

    /**
     * 获取兑换记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('reward:exchange:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rewardExchangeService.selectRewardExchangeById(id));
    }

    /**
     * 新增兑换记录
     */
    //@PreAuthorize("@ss.hasPermi('reward:exchange:add')")
    @Log(title = "兑换记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RewardExchange rewardExchange)
    {
        return toAjax(rewardExchangeService.insertRewardExchange(rewardExchange));
    }

    /**
     * 修改兑换记录
     */
    //@PreAuthorize("@ss.hasPermi('reward:exchange:edit')")
    @Log(title = "兑换记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RewardExchange rewardExchange)
    {
        return toAjax(rewardExchangeService.updateRewardExchange(rewardExchange));
    }

    /**
     * 删除兑换记录
     */
    //@PreAuthorize("@ss.hasPermi('reward:exchange:remove')")
    @Log(title = "兑换记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rewardExchangeService.deleteRewardExchangeByIds(ids));
    }
}
